// 封装购物车相关的API函数
import request from '@/utils/request'

/**
 * 获取商品最新价格 库存 是否有效
 * @param skuId
 */
export const getNewCartGoods = (skuId) => {
  return request(`/goods/stock/${skuId}`, 'get')
}

/**
 *  获取商品对应的sku数据
 *  @param {String} skuId - SKU id
 */
export const getGoodsSku = (skuId) => {
  return request(`/goods/sku/${skuId}`, 'get')
}

/**
 * 合并购物车
 * @param cartList 购物车列表
 * @returns {AxiosPromise}
 */
export const mergeCart = (cartList) => {
  return request('/member/cart/merge', 'post', cartList)
}

/**
 * 获取购物车信息
 * @param cartList
 * @returns {*}
 */
export const findCart = (cartList) => {
  return request('/member/cart', 'get')
}

/**
 * 加入购物车
 * @param skuId
 * @param count
 * @returns {*}
 */
export const insertCart = ({
  skuId,
  count
}) => {
  return request('/member/cart', 'post', {
    skuId,
    count
  })
}

/**
 * 删除购物车商品，支持批量
 * @param ids Array
 * @returns {*}
 */
export const deleteCart = (ids) => {
  return request('/member/cart', 'delete', { ids })
}

/**
 * 更新购物车（支持状态修改）
 * @param skuId
 * @param selected
 * @param count
 * @returns {*}
 */
export const updateCart = ({ skuId, selected, count }) => {
  return request(`/member/cart/${skuId}`, 'put', { selected, count })
}

/**
 * 全选 取消全选
 * @param selected
 * @param ids
 * @returns {*}
 */
export const checkAllCart = ({
  selected,
  ids
}) => {
  return request('/member/cart/selected', 'put', {
    selected,
    ids
  })
}
